<template>
  <BasicTable ref="basicTable" @register="registerTable" :rowSelection="rowSelection" width="100%">
    <template #action="{ record }">
      <!--操作栏-->
      <TableAction :actions="getTableAction(record)" />
    </template>
  </BasicTable>
  <!--弹窗区域-->
  <InventoryProfitModel @register="registerModal" @success="handleSuccess"></InventoryProfitModel>
</template>
<script lang="ts" setup>
  import { BasicTable, TableAction } from '/@/components/Table';
  import { columns } from './inventoryProfit.data';
  import { useListPage } from '/@/hooks/system/useListPage';
  import { useModal } from '/@/components/Modal';
  import { ref } from 'vue';
  import InventoryProfitModel from './components/InventoryProfitModel.vue';
  import { list } from './inventoryProfit.api';
  import { searchFormSchema } from './inventoryProfit.data';
  import { useI18n } from '/@/hooks/web/useI18n';
  const { t } = useI18n('asset.inventoryManagement.fields');
  //注册model
  const [registerModal, { openModal }] = useModal();
  const { tableContext } = useListPage({
    tableProps: {
      title: t('inventoryProfit'),
      api: list,
      columns,
      canResize: false,
      formConfig: {
        labelWidth: 120,
        schemas: searchFormSchema,
        autoSubmitOnEnter: true,
        showAdvancedButton: true,
        fieldMapToNumber: [],
        fieldMapToTime: [],
      },
      actionColumn: {
        width: 120,
        fixed: 'right',
      },
    },
  });
  const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext;
  const basicTable = ref<InstanceType<typeof BasicTable>>();
  /**
   * 详情
   */
  function handleDetail(record: Recordable) {
    openModal(true, {
      record,
      isUpdate: true,
      showFooter: false,
    });
    console.log('11', record);
  }
  /**
   * 成功回调
   */
  function handleSuccess() {
    (selectedRowKeys.value = []) && reload();
  }
  /**
   * 操作栏
   */
  function getTableAction(record) {
    return [
      {
        label: t('view'),
        onClick: handleDetail.bind(null, record),
      },
    ];
  }
</script>
